package cn.netbox.springmvc.dao;

import cn.netbox.springmvc.entity.User;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

/**
 * description:
 * date: 2022/3/26 20:22
 * author: Alex
 * version: 1.0
 */
@Repository
public class UserDao {
    private Map userMap = new HashMap<Integer, User>();

    {
        userMap.put(1, new User(1, "张三", "saddafasd"));
        userMap.put(2, new User(2, "李四", "sadd1651afasd"));
        userMap.put(3, new User(3, "王五", "sadda185185fasd"));
    }

    public User selectUserById(int id) {
        //       数据库交互
        return (User) userMap.get(id);

    }

    public Map<Integer, User> getAllUser() {
        return userMap;
    }

    public void create(User user) {
        userMap.put(user.getId(), user);
    }

    public void deletUserById(int id) {
        userMap.remove(id);
    }

    public void updateUser(User user){userMap.put(user.getId(),user);}
}
